<template>
	<div>
		<el-select class="w-ipt" v-model="search_name" remote filterable placeholder="请搜索地址添加"
			@change="handleCheckAddress" :remote-method="addressChange">
			<el-option v-for="item in address_list" :key="item.id" :label="item.address" :value="item.id">
			</el-option>
		</el-select>
	</div>
</template>

<script>
	import API from '@/api/index.js'

	export default {
		data() {
			return {
				address_list: [],
				search_name: this.address
			}
		},
		props: ['address'],
		watch: {
			address(val) {
        console.log(val)
				this.search_name = val;
			}
		},
		methods: {
			// 加载更多数据
			addressChange(val) {
				let self = this;
				self.search_name = val;
				self.$emit('getAddresses', {
					address_id: val
				})
				API.oneAddresses(self.search_name).then(res => {
					let data = res.data;
					self.address_list = data.data;
				}).catch(err => {
					self.$message.error(err.response.data.message)
				});
			},
			// 选中的地址
			handleCheckAddress(val) {
				let self = this;
				self.$emit('getAddresses', {
					address_id: val
				})
			},
		}
	}
</script>

<style scoped lang="scss">

</style>
